package com.chenzhou.product_sys.dao.impl;

import com.chenzhou.product_sys.common.BaseDAO;
import com.chenzhou.product_sys.common.DBuitl;
import com.chenzhou.product_sys.entity.Product;
import com.chenzhou.product_sys.entity.UserEntity;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@Repository
public class UserDAOImpl extends BaseDAO<UserEntity>{

    @Override
    protected List<UserEntity> resultSetToList(ResultSet rs) throws SQLException {
         List<UserEntity> list = new ArrayList<>();
         while(rs.next()){
             UserEntity u = new UserEntity();
             u.setUid(rs.getInt("uid"));
             u.setUname(rs.getString("uname"));
             u.setPwd(rs.getString("pwd"));
             u.setNichen(rs.getString("nickname"));
             u.setPhone(rs.getString("phone"));
             u.setAddress(rs.getString("address"));
             u.setMarkup(rs.getString("markup"));
             u.setIsadmin(rs.getString("isadmin"));
             list.add(u);
         }
        return list;
    }

    /**
     * 根据用户名和密码查询用户
     * @param
     * @return
     */
    public UserEntity queryUserByUnameAndPwd(String uname,String pwd){
        String sql = "select * from tbl_user where uname = ? and pwd = ?";
        Object[] objects = new Object[]{uname,pwd};
        List<UserEntity> list = this.execute_Query(sql,objects);
        if(list.size()>0){
            return list.get(0);
        }else{
            return null;
        }
    }
}
